﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity;
using System.Linq;

namespace h1
{
    public class Sqlite : DbContext
    {
        //您的上下文已配置为从您的应用程序的配置文件(App.config 或 Web.config)
        //使用“Sqlite”连接字符串。默认情况下，此连接字符串针对您的 LocalDb 实例上的
        //“h1.Sqlite”数据库。
        // 
        //如果您想要针对其他数据库和/或数据库提供程序，请在应用程序配置文件中修改“Sqlite”
        //连接字符串。
        public Sqlite()
            : base("name=Sqlite")
        {
            Database.SetInitializer(
                new DropCreateDatabaseIfModelChanges<Sqlite>());
        }
        public DbSet<School> Schools { get; set; }
        public DbSet<Class> Classes { get; set; }
        public DbSet<Student> Students { get; set; }

        //为您要在模型中包含的每种实体类型都添加 DbSet。有关配置和使用 Code First  模型
        //的详细信息，请参阅 http://go.microsoft.com/fwlink/?LinkId=390109。

        // public virtual DbSet<MyEntity> MyEntities { get; set; }
    }
    public class School
    {
        [Key]
        public string SchoolID { get; set; }
        public string SchoolName { get; set; }
        public string SchoolDescription { get; set; }
        public List<Class> classes { get; set; }
    }

    public class Class
    {
        [Key]
        public string ClassID { get; set; }
        public string SchoolID { get; set; }
        public School school { get; set; }
        public string ClassName { get; set; }
        public string grade { get; set; }
        public int numOfStudent
        {
            get
            {
                return students.Count;
            }
        }
        public List<Student> students { get; set; }
    }

    public class Student
    {
        [Key]
        public string StudentID { get; set; }
        public string ClassID { get; set; }
        public Class Class { get; set; }
        public string StudentName { get; set; }

        public string gender { get; set; }
        public int age { get; set; }
    }

    //public class MyEntity
    //{
    //    public int Id { get; set; }
    //    public string Name { get; set; }
    //}
}